Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

alphanum-sort

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alphanum-sort

Alphanumeric sorting algorithm

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.1M
increased by8.62%
Maintainers
1
Weekly downloads
 
Created

What is alphanum-sort?

The alphanum-sort npm package is designed to provide developers with a robust solution for sorting arrays containing alphanumeric strings. Unlike the default sort in JavaScript, which can produce unexpected results with mixed content, alphanum-sort handles numbers within strings intelligently, ensuring a natural ordering. This is particularly useful for sorting lists of files, version numbers, or any other strings where numerical values are embedded within text.

What are alphanum-sort's main functionalities?

Basic alphanumeric sorting

This feature demonstrates the basic usage of alphanum-sort to sort an array of strings containing numbers in a way that 'item10' comes after 'item2', reflecting a natural ordering that humans would expect.

var alphanumSort = require('alphanum-sort');
var sortedArray = alphanumSort(['item1', 'item10', 'item2']);
console.log(sortedArray); // ['item1', 'item2', 'item10']

Case insensitive sorting

This feature shows how to perform a case-insensitive sort, treating uppercase and lowercase letters as equivalent for sorting purposes.

var alphanumSort = require('alphanum-sort');
var sortedArray = alphanumSort(['Item1', 'item10', 'Item2'], { insensitive: true });
console.log(sortedArray); // ['Item1', 'Item2', 'item10']

Sorting with custom character groupings

This feature illustrates the ability to customize sorting behavior further, such as by specifying a custom order for characters, allowing for highly tailored sorting logic.

var alphanumSort = require('alphanum-sort');
var sortedArray = alphanumSort(['item1', 'item10', 'item2'], { custom: { order: 'a' } });
console.log(sortedArray); // Custom sorting based on provided options

Other packages similar to alphanum-sort

Keywords

FAQs

Package last updated on 03 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc